<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of VMT_ReadFiles_SonTek</title>
  <meta name="keywords" content="VMT_ReadFiles_SonTek">
  <meta name="description" content="Read in multiple MAT output files from SonTek RSL v1.5-3.60.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- menu.html trunk -->
<h1>VMT_ReadFiles_SonTek
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>Read in multiple MAT output files from SonTek RSL v1.5-3.60.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [zPathName,zFileName,savefile,A,z] = VMT_ReadFiles_SonTek(zPathName,zFileName) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> Read in multiple MAT output files from SonTek RSL v1.5-3.60.

 Added save path functionality (PRJ, 6-23-10)
 (adapted from code by J. Czuba)

 See also: parseSonTekVMT (utils folder)

 Frank L. Engel, USGS
 Last modified: 03/27/2014</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT.html" class="code" title="function varargout = VMT(varargin)">VMT</a>	--- THE VELOCITY MAPPING TOOLBOX ---</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function A = initStructure(z)</a></li></ul>

<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [zPathName,zFileName,savefile,A,z] = VMT_ReadFiles_SonTek(zPathName,zFileName)</a>
0002 <span class="comment">% Read in multiple MAT output files from SonTek RSL v1.5-3.60.</span>
0003 <span class="comment">%</span>
0004 <span class="comment">% Added save path functionality (PRJ, 6-23-10)</span>
0005 <span class="comment">% (adapted from code by J. Czuba)</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% See also: parseSonTekVMT (utils folder)</span>
0008 <span class="comment">%</span>
0009 <span class="comment">% Frank L. Engel, USGS</span>
0010 <span class="comment">% Last modified: 03/27/2014</span>
0011 
0012 
0013 
0014 <span class="comment">%% Read in multiple MAT files Files</span>
0015 <span class="comment">% This program reads in multiple ASCII text files into a single structure.</span>
0016 
0017 <span class="keyword">if</span> ischar(zFileName)
0018     zFileName = {zFileName};
0019 <span class="keyword">elseif</span> iscellstr(zFileName)
0020     zFileName = sort(zFileName);       
0021 <span class="keyword">end</span>
0022 <span class="comment">%msgbox('Loading Data...','VMT Status','help','replace')</span>
0023 
0024 <span class="comment">%% Read in Selected Files</span>
0025 <span class="comment">% Initialize the data structure</span>
0026 z = length(zFileName);
0027 A = <a href="#_sub1" class="code" title="subfunction A = initStructure(z)">initStructure</a>(z);
0028 
0029 <span class="comment">% Begin master loop</span>
0030 <span class="keyword">for</span> zi=1:z
0031     <span class="comment">% Open txt data file</span>
0032     fileName = fullfile(zPathName,zFileName{zi});
0033 
0034 
0035     <span class="comment">% parseSonTekVMT reads the data from an RSL MAT output file and puts</span>
0036     <span class="comment">% the data in a Matlab data structure with major groups of:</span>
0037     <span class="comment">% Sup - supporing data</span>
0038     <span class="comment">% Wat - water data</span>
0039     <span class="comment">% Nav - navigation data including GPS.</span>
0040     <span class="comment">% Sensor - Sensor data</span>
0041     <span class="comment">% Q - discharge related data</span>
0042 
0043     <span class="keyword">try</span>
0044         [A(zi)]=parseSonTekVMT(fileName);
0045         
0046         [~,file_name,extension] = fileparts(fileName);
0047         new_message = strrep([<span class="string">'Loading file '</span> file_name extension],<span class="string">'_'</span>,<span class="string">'\_'</span>);
0048 <span class="comment">%         if ishandle(h_waitbar)</span>
0049 <span class="comment">%             waitbar(zi/z,h_waitbar,new_message)</span>
0050 <span class="comment">%         else</span>
0051 <span class="comment">%             h_waitbar = waitbar(zi/z,new_message,'Name','Loading Files');</span>
0052 <span class="comment">%         end</span>
0053 
0054     <span class="keyword">catch</span> err
0055         
0056         erstg = {<span class="string">'                                                      '</span>,<span class="keyword">...</span>
0057                  <span class="string">'An unknown error occurred when reading the ASCII file.'</span>,<span class="keyword">...</span>
0058                  <span class="string">'Occasionally this occurs due to a corrupt ASCII file with'</span>,<span class="keyword">...</span>
0059                  <span class="string">'formatting errors. Please regenerate the ASCII file and '</span>,<span class="keyword">...</span>
0060                  <span class="string">'retry loading into VMT. An error may also occur if there '</span>,<span class="keyword">...</span>
0061                  <span class="string">'are white spaces or special characters (e.g. *?&lt;&gt;|) in '</span>,<span class="keyword">...</span>
0062                  <span class="string">'the filenames or paths. Ensure no such spaces or '</span>,<span class="keyword">...</span>
0063                  <span class="string">'characters exist and try loading the files again.'</span>};
0064         
0065         <span class="keyword">if</span> isdeployed
0066         errLogFileName = fullfile(pwd,<span class="keyword">...</span>
0067             [<span class="string">'errorLog'</span> datestr(now,<span class="string">'yyyymmddHHMMSS'</span>) <span class="string">'.txt'</span>]);
0068         msgbox({erstg;<span class="keyword">...</span>
0069             [<span class="string">'  Error code: '</span> err.identifier];<span class="keyword">...</span>
0070             [<span class="string">'Error details are being written to the following file: '</span>];<span class="keyword">...</span>
0071             errLogFileName},<span class="keyword">...</span>
0072             <span class="string">'VMT Status: Unexpected Error'</span>,<span class="keyword">...</span>
0073             <span class="string">'error'</span>);
0074         fid = fopen(errLogFileName,<span class="string">'W'</span>);
0075         fwrite(fid,err.getReport(<span class="string">'extended'</span>,<span class="string">'hyperlinks'</span>,<span class="string">'off'</span>));
0076         fclose(fid);
0077         rethrow(err)
0078     <span class="keyword">else</span>
0079         msgbox([<span class="string">'An unexpected error occurred. Error code: '</span> err.identifier],<span class="keyword">...</span>
0080             <span class="string">'VMT Status: Unexpected Error'</span>,<span class="keyword">...</span>
0081             <span class="string">'error'</span>);
0082         rethrow(err);
0083     <span class="keyword">end</span>
0084     <span class="keyword">end</span>
0085     
0086     <span class="comment">% Check the units to ensure they are metric</span>
0087     
0088     <span class="keyword">if</span> ~strcmp(A(zi).Sup.units(1,:),<span class="string">'cm'</span>)
0089         erstg = {<span class="string">'                                                      '</span>,<span class="keyword">...</span>
0090                  <span class="string">'Units in ASCII file are not metric.  VMT only accepts data'</span><span class="keyword">...</span>
0091                  <span class="string">'in metric units.  Please change the units in WinRiver II'</span><span class="keyword">...</span>
0092                  <span class="string">'and export your ASCII files again before reloading into VMT.'</span>};
0093         errordlg([zFileName(zi) erstg],<span class="string">'VMT Status'</span>,<span class="string">'replace'</span>);
0094         error(<span class="string">'VMT:unitsChk'</span>, <span class="string">'Input not in metic units'</span>)
0095     <span class="keyword">end</span>
0096 
0097 <span class="keyword">end</span>
0098 
0099 <span class="comment">% Get rid of the waitbar</span>
0100 <span class="comment">% if ishandle(h_waitbar)</span>
0101 <span class="comment">%     delete(h_waitbar)</span>
0102 <span class="comment">% end</span>
0103 
0104 <span class="comment">% Save data returned by tfile to .mat with same prefix as ASCII</span>
0105 [file_root_name,the_rest] = strtok(zFileName,<span class="string">'.'</span>);
0106 <span class="keyword">for</span> i = 1:length(zFileName)
0107     d1 = file_root_name{i};
0108     date{i} = d1(1:8);
0109     time{i} = d1(9:end);
0110 <span class="keyword">end</span>
0111 
0112 save_dir = fullfile(zPathName,<span class="string">'VMTProcFiles'</span>);
0113 [~,mess,~] = mkdir(save_dir); 
0114 <span class="comment">% disp(mess)</span>
0115 
0116 savefile = [date{1} <span class="string">'_s'</span> time{1} <span class="string">'_e'</span> time{end} <span class="string">'.mat'</span>];
0117 savefile = fullfile(save_dir,savefile);
0118 
0119 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%</span>
0120 <span class="comment">% Embedded Functions %</span>
0121 <span class="comment">%%%%%%%%%%%%%%%%%%%%%%</span>
0122 
0123 <a name="_sub1" href="#_subfunctions" class="code">function A = initStructure(z)</a>
0124    Sup = struct(<span class="string">'absorption_dbpm'</span>,{}, <span class="keyword">...</span>
0125                 <span class="string">'bins'</span>,{}, <span class="keyword">...</span>
0126                 <span class="string">'binSize_cm'</span>,{}, <span class="keyword">...</span>
0127                 <span class="string">'nBins'</span>,{}, <span class="keyword">...</span>
0128                 <span class="string">'blank_cm'</span>,{}, <span class="keyword">...</span>
0129                 <span class="string">'draft_cm'</span>,{}, <span class="keyword">...</span>
0130                 <span class="string">'ensNo'</span>,{}, <span class="keyword">...</span>
0131                 <span class="string">'nPings'</span>,{}, <span class="keyword">...</span>
0132                 <span class="string">'noEnsInSeg'</span>,{}, <span class="keyword">...</span>
0133                 <span class="string">'noe'</span>,{}, <span class="keyword">...</span>
0134                 <span class="string">'note1'</span>,{}, <span class="keyword">...</span>
0135                 <span class="string">'note2'</span>,{}, <span class="keyword">...</span>
0136                 <span class="string">'intScaleFact_dbpcnt'</span>,{}, <span class="keyword">...</span>
0137                 <span class="string">'intUnits'</span>,{}, <span class="keyword">...</span>
0138                 <span class="string">'vRef'</span>,{}, <span class="keyword">...</span>
0139                 <span class="string">'wm'</span>,{}, <span class="keyword">...</span>
0140                 <span class="string">'units'</span>,{}, <span class="keyword">...</span>
0141                 <span class="string">'year'</span>,{}, <span class="keyword">...</span>
0142                 <span class="string">'month'</span>,{}, <span class="keyword">...</span>
0143                 <span class="string">'day'</span>,{}, <span class="keyword">...</span>
0144                 <span class="string">'hour'</span>,{}, <span class="keyword">...</span>
0145                 <span class="string">'minute'</span>,{}, <span class="keyword">...</span>
0146                 <span class="string">'second'</span>,{}, <span class="keyword">...</span>
0147                 <span class="string">'sec100'</span>,{}, <span class="keyword">...</span>
0148                 <span class="string">'timeElapsed_sec'</span>,{}, <span class="keyword">...</span>
0149                 <span class="string">'timeDelta_sec100'</span>,{});
0150    Wat = struct(<span class="string">'binDepth'</span>,{}, <span class="keyword">...</span>
0151                 <span class="string">'backscatter'</span>,{}, <span class="keyword">...</span>
0152                 <span class="string">'vDir'</span>,{}, <span class="keyword">...</span>
0153                 <span class="string">'vMag'</span>,{}, <span class="keyword">...</span>
0154                 <span class="string">'vEast'</span>,{}, <span class="keyword">...</span>
0155                 <span class="string">'vError'</span>,{}, <span class="keyword">...</span>
0156                 <span class="string">'vNorth'</span>,{}, <span class="keyword">...</span>
0157                 <span class="string">'vVert'</span>,{}, <span class="keyword">...</span>
0158                 <span class="string">'percentGood'</span>,{});
0159    Nav = struct(<span class="string">'bvEast'</span>,{}, <span class="keyword">...</span>
0160                 <span class="string">'bvError'</span>,{}, <span class="keyword">...</span>
0161                 <span class="string">'bvNorth'</span>,{}, <span class="keyword">...</span>
0162                 <span class="string">'bvVert'</span>,{}, <span class="keyword">...</span>
0163                 <span class="string">'depth'</span>,{}, <span class="keyword">...</span>
0164                 <span class="string">'dsDepth'</span>,{}, <span class="keyword">...</span>
0165                 <span class="string">'dmg'</span>,{}, <span class="keyword">...</span>
0166                 <span class="string">'length'</span>,{}, <span class="keyword">...</span>
0167                 <span class="string">'totDistEast'</span>,{}, <span class="keyword">...</span>
0168                 <span class="string">'totDistNorth'</span>,{}, <span class="keyword">...</span>
0169                 <span class="string">'altitude'</span>,{}, <span class="keyword">...</span>
0170                 <span class="string">'altitudeChng'</span>,{}, <span class="keyword">...</span>
0171                 <span class="string">'gpsTotDist'</span>,{}, <span class="keyword">...</span>
0172                 <span class="string">'gpsVariable'</span>,{}, <span class="keyword">...</span>
0173                 <span class="string">'gpsVeast'</span>,{}, <span class="keyword">...</span>
0174                 <span class="string">'gpsVnorth'</span>,{}, <span class="keyword">...</span>
0175                 <span class="string">'lat_deg'</span>,{}, <span class="keyword">...</span>
0176                 <span class="string">'long_deg'</span>,{}, <span class="keyword">...</span>
0177                 <span class="string">'nSats'</span>,{}, <span class="keyword">...</span>
0178                 <span class="string">'hdop'</span>,{});
0179    Sensor = struct(<span class="string">'pitch_deg'</span>,{}, <span class="keyword">...</span>
0180                    <span class="string">'roll_deg'</span>,{}, <span class="keyword">...</span>
0181                    <span class="string">'heading_deg'</span>,{}, <span class="keyword">...</span>
0182                    <span class="string">'temp_degC'</span>,{});
0183      Q = struct(<span class="string">'endDepth'</span>,{}, <span class="keyword">...</span>
0184                 <span class="string">'endDist'</span>,{}, <span class="keyword">...</span>
0185                 <span class="string">'bot'</span>,{}, <span class="keyword">...</span>
0186                 <span class="string">'end'</span>,{}, <span class="keyword">...</span>
0187                 <span class="string">'meas'</span>,{}, <span class="keyword">...</span>
0188                 <span class="string">'start'</span>,{}, <span class="keyword">...</span>
0189                 <span class="string">'top'</span>,{}, <span class="keyword">...</span>
0190                 <span class="string">'unit'</span>,{}, <span class="keyword">...</span>
0191                 <span class="string">'startDepth'</span>,{}, <span class="keyword">...</span>
0192                 <span class="string">'startDist'</span>,{});
0193             A(z).Sup = Sup;
0194             A(z).Wat = Wat;
0195             A(z).Nav = Nav;
0196             A(z).Sensor = Sensor;
0197             A(z).Q = Q;
0198             
0199             <span class="comment">% [EOF] initStructure</span></pre></div>
<hr><address>Generated on Wed 04-Jun-2014 14:21:02 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>